package com.reminder.server;

import java.util.List;

import com.reminder.annotation.ServiceMethod;
import com.reminder.shared.TaskChange;

public class ReminderService {
	static DataStore db = new DataStore();

	@ServiceMethod
	public static Task createTask() {
		return db.update(new Task());
	}
	
	
	@ServiceMethod
	public static void createUserGroup(String acceptEmail) {
		db.updateUserGroup(acceptEmail);
	}
	


	@ServiceMethod
	public static Task readTask(Long id) {
		return db.find(id);
	}
	
	@ServiceMethod
	public static List<String> getInvites() throws NoSuchFieldException {	
		return db.findAcceptEmails();
	}
	
	@ServiceMethod
	public static List<String> getInvitesNotAccepted() throws NoSuchFieldException {	
		return db.findAcceptEmailsFalse();
	}
	

	@ServiceMethod
	public static Task updateTask(Task task) {
		task.setEmailAddress(DataStore.getUserEmail());
		task = db.update(task);
		DataStore.sendC2DMUpdate(TaskChange.UPDATE + TaskChange.SEPARATOR + task.getId());
		return task;

	}

	@ServiceMethod
	public static void deleteTask(Task task) {
		db.delete(task.getId());

	}

	@ServiceMethod
	public static List<Task> queryTasks() {
		return db.findAll();
	}
	@ServiceMethod
	public static void updateUserGroupInviteToTrue(String acceptInvite) {
		db.updateUserGroupInvite(acceptInvite);
	}
	
	@ServiceMethod
	public static List<Task> findAllNotNotified() {
		return db.findAllNotNotified();
	}
	
	@ServiceMethod
	public static void updateTasksNotified(long taskId) {
		db.updateTasksNotified(taskId);
	}
	
}
